import { Component } from "react";

export default class Login extends Component {
  handleLogin = () => {
    // 1. 修改 window.isLogin 状态
    window.isLogin = true;

    // 2. 获取url地址上 redirect 参数的值
    const searchParams = new URLSearchParams(this.props.location.search);
    const redirect = searchParams.get("redirect") || "/";
    console.log("redirect", redirect);

    // 3. 使用 redirect 来跳转
    this.props.history.replace(redirect);
  };

  render() {
    return (
      <div>
        <h2>Login</h2>
        <button onClick={this.handleLogin}>登录，点一下就登录成功</button>
      </div>
    );
  }
}
